/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package muhnes.sizoo.vista;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import muhnes.sizoo.dal.OrdenDao;
import muhnes.sizoo.dal.OrdenDaoImpl;
import muhnes.sizoo.modelo.Orden;
/**
 *
 * @author Ricardo Orellana
 */
public class OrdenConverter implements Converter {
    
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Object valorObject = null;
        
        if( value != null && value != "" ) {
            OrdenDao dao = new OrdenDaoImpl();
            valorObject = dao.buscarPorId( Integer.parseInt( value ) );
        }
        
        return valorObject;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        String valorString = "";
        
        if( value != null && value instanceof Orden ) {
            valorString = String.valueOf( ((Orden) value).getCodigoorden() );
        }
        
        return valorString;
    }

}
